package a_java_48_day.day4;
/**
 * 进制转化
 */

import java.util.*;
public class Main2 {
    public static char change(int rem) {
        char changeChar = ' ';
        if (rem == 10) {
            changeChar = 'A';
        } else if (rem == 11) {
            changeChar = 'B';
        } else if (rem == 12) {
            changeChar = 'C';
        } else if (rem == 13) {
            changeChar = 'D';
        } else if (rem == 14) {
            changeChar = 'E';
        } else if (rem == 15) {
            changeChar = 'F';
        } else {
            changeChar = 'G';
        }
        return changeChar;
    }
    public static List addList(int M, int N, List list) {
        while (M != 0) {
            int rem = M % N;
            if (rem >= 10 && rem < 16) {
                char remChar = change(rem);
                list.add(remChar);
            } else {
                list.add(rem);
            }
            int inte = M / N;
            M = inte;
        }
        return list;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        int N = sc.nextInt();
        List list = new LinkedList();
        int sum = 0;
        if (M == 0) {
            System.out.print(0);
        } else if (M < 0) {
            M = Math.abs(M);
            list=addList(M,N,list);
            list.add('-');
        } else {
            list=addList(M,N,list);
        }
        for (int i = list.size() - 1; i >= 0; i--) {
            System.out.print(list.get(i));
        }
    }
}